//
//  MyaskViewController.swift
//  DianShangWen
//
//  Created by 周文轩 on 15/4/27.
//  Copyright (c) 2015年 &#21608;&#25991;&#36713;. All rights reserved.
//

import UIKit

class MyaskViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate {
    
    @IBOutlet weak var myaskButton: UIButton!
    @IBOutlet weak var inquiryButton: UIButton!
    @IBOutlet weak var myaskView: UIView!
    @IBOutlet weak var inquiryView: UIView!
    @IBOutlet weak var myaskScrollView: UIScrollView!
    @IBOutlet weak var myaskTableView: UITableView!
    @IBOutlet weak var inquiryTableView: UITableView!
    
    @IBOutlet weak var myaskScrollViewWith: NSLayoutConstraint!

    override func viewDidLoad() {
        super.viewDidLoad()

        myaskScrollViewWith.constant = UIScreen.mainScreen().bounds.size.width*2
        
        creatScrollView()
        creatTableViewController()
        
        // Do any additional setup after loading the view.
    }
    
    func creatScrollView() {
        myaskScrollView.delegate = self
    }
    
    func creatTableViewController() {
        myaskTableView.delegate = self
        myaskTableView.dataSource = self
        inquiryTableView.delegate = self
        inquiryTableView.dataSource = self
    }
    
    func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
        switch scrollView.contentOffset.x {
        case 0:
            inquiryButtonTouch(nil)
        case self.view.frame.size.width:
            myaskButtonTouch(nil)
        default:
            println("Not Dragging")
        }
    }
    
    @IBAction func myaskButtonTouch(sender: AnyObject!) {
        myaskButton.setTitleColor(ResourceProvider.sharedInstance.redColoer, forState: UIControlState.Normal)
        myaskView.backgroundColor = ResourceProvider.sharedInstance.redColoer
        inquiryButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        inquiryView.backgroundColor = UIColor.whiteColor()
        
        myaskScrollView.contentOffset.x = self.view.frame.size.width
    }
    
    @IBAction func inquiryButtonTouch(sender: AnyObject!) {
        inquiryButton.setTitleColor(ResourceProvider.sharedInstance.redColoer, forState: UIControlState.Normal)
        inquiryView.backgroundColor = ResourceProvider.sharedInstance.redColoer
        myaskButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        myaskView.backgroundColor = UIColor.whiteColor()
        
        myaskScrollView.contentOffset.x = 0
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("myaskTableViewCell", forIndexPath: indexPath) as! UITableViewCell
        
        return cell
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
